﻿@model Citi.Scheduler.WebUi.Models.LibraryVersionModel
<script type="text/javascript">
    $(function () {
        $("#ChangeType,#Type").change(function () {
            if ($('#ChangeType :selected').index() == 0 || $('#Type :selected').index() == 0)
                return;

            $.ajax({
                url: '@Url.Action("GetNextVersion")',
                type: "post",
                data: { libraryId: $('#LibraryId').val(), changeType: $('#ChangeType :selected').val(), libraryType: $('#Type :selected').val() },
                success: function (json) {
                    $('#spanVersion').html(json.version);
                    $('#Version').val(json.version);
                }
            });
        });
    });
</script>
@*@using (Ajax.BeginForm("Create", "LibraryVersion", new AjaxOptions { UpdateTargetId = "divIndexLibraryHistory", OnComplete = "$('#divCreateLibraryVersion').hide();", InsertionMode = InsertionMode.Replace }, new { id = "formLibraryVersion" }))*@
@using (Ajax.BeginForm("Create", "LibraryVersion", new AjaxOptions { UpdateTargetId = "divIndexLibraryHistory", InsertionMode = InsertionMode.Replace }, new { id = "formLibraryVersion" }))
{
    <div style="float: left; width: 50%;">
        <div class="editor-label">
            @Html.LabelFor(model => model.ChangeType)
            @Html.DropDownListFor(model => model.ChangeType, (IEnumerable<SelectListItem>)ViewBag.ChangeTypes)
        </div>
    </div>

    <div style="float: right; width: 50%;">
        <div class="editor-label">
            @Html.LabelFor(model => model.Type)
            @Html.DropDownListFor(model => model.Type, (IEnumerable<SelectListItem>)ViewBag.Types)
        </div>
    </div>
    
    <div style="float: left; width: 50%;">
        <div class="editor-label">
            @Html.LabelFor(model => model.Version)
            @Html.HiddenFor(model => model.Version)
            <span id="spanVersion"></span>
        </div>
    </div>

    <div style="float: right; width: 50%;">
        <div class="editor-label">
            @Html.LabelFor(model => model.UserId)
            @Html.DropDownListFor(model => model.UserId, (IEnumerable<SelectListItem>)ViewBag.Users)
            @Html.ValidationMessageFor(model => model.UserId)
        </div>
    </div>
    <div style="clear: both;">
    </div>
    @Html.HiddenFor(model => model.LibraryId)

    <div class="editor-label">
        @Html.LabelFor(model => model.ChangeDescription)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.ChangeDescription)
        @Html.ValidationMessageFor(model => model.ChangeDescription)
    </div>

    <p>
        <input type="submit" value="Create" />
    </p>
}